package cn.kgc.springcloud.service.impl;

import cn.kgc.springcloud.client.TagClient;
import cn.kgc.springcloud.entity.Tag;
import cn.kgc.springcloud.vo.ClazzVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.springcloud.entity.Clazz;
import cn.kgc.springcloud.service.ClazzService;
import cn.kgc.springcloud.mapper.ClazzMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author mengshun
* @description 针对表【t_clazz】的数据库操作Service实现
* @createDate 2023-10-19 09:49:56
*/
@Service
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz> implements ClazzService{

    @Resource
    private ClazzMapper clazzMapper;


    @Resource
    private TagClient tagClient;

    @Override
    public List<ClazzVO> getClazzVOList() {

        //获取班级列表
        List<Clazz> clazzs = clazzMapper.selectList(null);

        List<ClazzVO> collect = clazzs.stream().map(clazz -> {
            ClazzVO clazzVO = new ClazzVO();
            // 对象的拷贝
            BeanUtils.copyProperties(clazz,clazzVO);
            // tag
            Integer tagid = clazz.getTagid();
            // 发送http请求 tag服务  根据标签id 获取标签对象
            Tag tag = tagClient.getById(tagid);
            clazzVO.setTag(tag);
            return clazzVO;
        }).collect(Collectors.toList());


        return collect;
    }
}




